// 自动生成模板Category
package cms

import (
	"gitcode.com/G-YT/baoyou/server/global"
)

// 分类 结构体  Category
type Category struct {
	global.GvaModel
	Name        *string     `json:"name" form:"name" gorm:"column:name;" binding:"required"`             //名称
	Description *string     `json:"description" form:"description" gorm:"column:description;type:text;"` //描述
	SortOrder   *int64      `json:"sortOrder" form:"sortOrder" gorm:"column:sort_order;"`                //排序
	Children    []*Category `json:"children" gorm:"-"`                                                   //子节点
	ParentID    int         `json:"parentID" gorm:"column:parent_id;comment:父节点"`
}

// TableName 分类 Category自定义表名 by_cms_categories
func (Category) TableName() string {
	return "by_cms_categories"
}

// GetChildren 实现TreeNode接口
func (s *Category) GetChildren() []*Category {
	return s.Children
}

// SetChildren 实现TreeNode接口
func (s *Category) SetChildren(children *Category) {
	s.Children = append(s.Children, children)
}

// GetID 实现TreeNode接口
func (s *Category) GetID() int {
	return int(s.ID)
}

// GetParentID 实现TreeNode接口
func (s *Category) GetParentID() int {
	return s.ParentID
}
